/*
 * @(#)HouseProvidentSqlImpl.java       2011-8-8
 *
 * Copyright（c）2010 北京云狐软件有限公司保留所有权利.
 */
package com.yunhoo.provident.db.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.provident.model.HouseProvident;
import com.yunhoo.provident.model.PersonProvident;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.LoginParam;

import java.sql.SQLException;
import java.util.List;

/**
 * 类
 * <code>HouseProvidentSqlImpl</code>
 *
 * @author 胡开龙
 * @version 2011-8-8
 * @see java.lang.Class
 * @since jdk1.6
 */
public class HouseProvidentSqlImpl {

    private static SqlMapClient sqlMap = IbatisTemplate.getSqlMapClient();

    public static void insertProvident(List<HouseProvident> providents) {
        String orgCode = LoginParam.getOrg().getCode();
        try {
            sqlMap.startTransaction();
            sqlMap.startBatch();
            for (HouseProvident busi : providents) {
                busi.setOrgCode(orgCode);
                sqlMap.insert("houseProvident.insertProvident", busi);
            }
            sqlMap.executeBatch();
            sqlMap.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                sqlMap.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void delProvidentBookForImpNewData() {
        IbatisTemplate.delete("houseProvident.delProvidentBookForImpNewData", getOrgCode());
    }

    public static void insertProvidentBook(List<PersonProvident> providents) {
        String orgCode = getOrgCode();
        try {
            sqlMap.startTransaction();
            sqlMap.startBatch();
            for (PersonProvident pergjj : providents) {
                pergjj.setOrgCode(orgCode);
                sqlMap.insert("houseProvident.insertProvidentBook", pergjj);
            }
            sqlMap.executeBatch();
            sqlMap.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                sqlMap.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    private static String getOrgCode() {
        return LoginParam.getOrg().getCode();
    }
}
